package in.muton.edushare.jquery;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;

public class AccordionContainer extends Panel {
	private static final long serialVersionUID = -8755928881809334576L;
	private List<AccordionListItem> listItems = new ArrayList<AccordionListItem>();
	public AccordionContainer(String id) {
		super(id);
		add(new ListView<AccordionListItem>("accordionList", listItems) {
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(ListItem<AccordionListItem> arg0) {
				AccordionListItem item = arg0.getModelObject();
				arg0.add(new Label("accordionListHead",item.getHeading()));
				arg0.add(item.getPanel());
				arg0.setRenderBodyOnly(true);
			}
		});
	}
	
	public void addNewAccordionPanel(String heading, Panel panel){
		listItems.add(new AccordionListItem(heading, panel));
	}
	
	public String getNextPanelId(){
		return "accordionListItem";
	}
	
	public class AccordionListItem implements Serializable{
		private static final long serialVersionUID = 4898432858817107326L;
		private String heading;
		private Panel panel;
		public AccordionListItem(String heading, Panel panel) {
			super();
			this.heading = heading;
			this.panel = panel;
		}

		public String getHeading() {
			return heading;
		}

		public Panel getPanel() {
			return panel;
		}
	}	
}
